package com.chixing.controller;


import com.chixing.entity.Comment;
import com.chixing.service.ICommentService;
import com.chixing.utils.Result;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author smith
 * @since 2025-09-30
 */
@CrossOrigin
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;
    // 保存评论
    @PostMapping
    public Result saveComment(@RequestBody Comment comment){
        return commentService.saveComment(comment);
    }
    // 用户分页查询自己的评论
    @GetMapping(value = {"page/{pageNum}/{userId}","/page/{userId}"})
    public Result getAllComments(@PathVariable(value = "pageNum",required = false) Integer pageNum,
                                 @PathVariable("userId") Long userId) {
        if (pageNum == null) {
            pageNum = 1;
        }
        return commentService.getCommentAll(pageNum, userId);
    }


    // 删除评论
    @DeleteMapping("{commentId}/{userId}")
    public Result deleteComment(@PathVariable("userId") Long userId,
                                @PathVariable("commentId") Long commentId){
        return commentService.deleteComment(userId,commentId);
    }

}